package com.nandi.deviceinstall.model


import com.nandi.deviceinstall.bean.*
import com.nandi.deviceinstall.contract.EquimentStepContract
import com.nandi.deviceinstall.contract.LoginContract
import com.nandi.deviceinstall.net.RetrofitClient
import com.nandi.deviceinstall.net.dto.TapAddDTO

import io.reactivex.Flowable
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File


class EquipmentStepModel : EquimentStepContract.Model {

    private val apiService = RetrofitClient.getInstance()!!.api!!

    override fun executeListDisName(token: String, disasterName: String, town: String): Flowable<DisNameBean> {
        return apiService.listDisName(token, disasterName, town)
    }

    override fun executeAddTap(token: String, params: TapAddDTO): Flowable<TapAddResultBean> {
        return apiService.addTap(token, params)
    }

    override fun executeUpdateTap(token: String, params: TapAddDTO): Flowable<TapAddResultBean> {
        return apiService.updateTap(token,params)
    }

    override fun executeDisNum(token: String, disName: String, areaCode: String): Flowable<DisNumBean> {
        return apiService.getDisNum(token,disName,areaCode)
    }

    override fun getListDisaster(token: String, areaCode: String): Flowable<DisasterBean> {
        return apiService.listDisaster(token, areaCode)
    }

    override fun getListCity(token: String, district: String): Flowable<CityBean> {
        return apiService.listCity(token, district)
    }

    override fun getListTown(token: String, id: Int): Flowable<TownBean> {
        return apiService.listTown(token, id)
    }

    override fun uploadPic(token: String, file: File, type: Int): Flowable<UploadPicBean> {
        val type = RequestBody.create(MediaType.parse("text/plain"), type.toString())
        val picFile = RequestBody.create(MediaType.parse("image/*"), file)
        val createFormData = MultipartBody.Part.createFormData("file", file.name, picFile)
        return apiService.uploadPic(token, createFormData, type)
    }

    override fun removePicFile(token: String, sourcePath: String, type: Int): Flowable<RemovePicBean> {
        return apiService.removePicFile(token, sourcePath, type)
    }
}
